package com.dc.refactoring._5_简化函数调用._6_ReplaceParameterWithExplicitMethods;

public class Employee {

    public static final int ENGINEER = 0;
    public static final int SALESMAN = 1;
    public static final int MANAGER = 2;

    // 原函数，当前是工厂方法，通过传参返回，对应对象
    static Employee create(int type) {
        switch (type) {
            case ENGINEER:
                return new Engineer();
            case SALESMAN:
                return new Salesman();
            case MANAGER:
                return new Manager();
            default:
                throw new IllegalArgumentException();
        }
    }

    // step 1 根据参数值尽量响应的新函数
    public static Employee createEngineer(){
        return new Engineer();
    }

    public static Employee createSalesman(){
        return new Salesman();
    }

    public static Employee createManager(){
        return new Manager();
    }

    // step 2 各个分支替换对新函数的调用
    static Employee create2(int type) {
        switch (type) {
            case ENGINEER:
                return Employee.createEngineer();
            case SALESMAN:
                return Employee.createSalesman();
            case MANAGER:
                return Employee.createManager();
            default:
                throw new IllegalArgumentException();
        }
    }

    // step 4 当调用端都修改完毕，删除原函数


    public static void main(String[] args){

        // 原
        Employee engineer1 = create(Employee.ENGINEER);


        // 新
        // step 3 修改原函数的每一个调用端，修改为上述某个合适的新函数
        Employee engineer2 = Employee.createEngineer();


    }



}
